package com.hliushi.learn.listener;

import com.hliushi.learn.bean.Reader;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

/**
 * @ClassName MyEventListener
 * @Description 自定义监听器, 监听MyEvent事件
 * @Author liushi
 * @Date 2021/7/8 16:11
 * @Version V1.0
 **/
@Component
public class MyEventListener implements ApplicationListener<MyEvent> {


    @Override
    public void onApplicationEvent(MyEvent myEvent) {
        // 把事件中的信息获取到
        Reader reader = myEvent.getReader();
        // 处理事件, 实际项目中可以通知别的微服务或者处理其他逻辑等等
        System.out.println("用户名: " + reader.getName());
        System.out.println("电话: " + reader.getTelcode());
    }
}
